#! /usr/bin/env python
"""Skeleton project file mainloop for new OLPCGames users"""
import olpcgames, pygame, logging 
from olpcgames import pausescreen

from lib.MenuPart import MenuPart
from lib.LoadPart import LoadPart
from lib.Loader   import Loader
from MentefactosActivity import MentefactosActivity

log = logging.getLogger( 'Mentefactos run' )
log.setLevel( logging.DEBUG )


    
class JigsawPuzzle(object):
    def __init__(self):
        self.screen = pygame.display.set_mode((800, 600),1)

    def main_loop(self):            
        clock  =  pygame.time.Clock()
        loader =  Loader("perros")
        
        #Se obtienen las imagenes de los atributos del diagrama
        pieces = loader.list_atributes()
        
        #Se obtiene el diagrama solucion
        orgimg = loader.load_solution()
        
        #Se crea el tablero del juego
        game = MentefactosActivity(pieces, orgimg, "perros")
    
        while 1:
            clock.tick(30)        
    
            for event in pygame.event.get():
                # Se hizo click en salir
                if event.type == pygame.QUIT:
                    return
                # Se envia el evento al menu para ser procesado
                game.event(event)    
                        
            game.update(self.screen)
            if game.next_part == -1:
                break

            pygame.display.flip()            

def main():
    try:
        import psyco
        psyco.full()
    except ImportError:
        pass

    pygame.init()

    g = JigsawPuzzle()
    g.main_loop()
 
if __name__ == '__main__': 
    main()



